package cz.uhk.ppro.entities;

import java.io.Serializable;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Uzivatel implements Serializable {
	/**
	 * Uživatel aplikace
	 */
	private static final long serialVersionUID = 1L;
	private String jmeno,prijmeni,login,heslo,skupina;
	@Id
	@GeneratedValue
	private int  id;
	
	public Uzivatel() {
		
	}
	
	public String getJmeno() {
		return jmeno;
	}
	
	public void setJmeno(String jmeno) {
		this.jmeno = jmeno;
	}
	
	public String getPrijmeni() {
		return prijmeni;
	}
	
	public void setPrijmeni(String prijmeni) {
		this.prijmeni = prijmeni;
	}
	
	public String getLogin() {
		return login;
	}
	
	public void setLogin(String login) {
		this.login = login;
	}
	
	public String getHeslo() {
		return heslo;
	}
	
	public void setHeslo(String heslo) throws NoSuchAlgorithmException {
		MessageDigest m = MessageDigest.getInstance("md5");
		m.reset();
		m.update(heslo.getBytes());
		byte[] digest = m.digest();
		BigInteger bigInt = new BigInteger(1,digest);
		String hashtext = bigInt.toString(16);
		while(hashtext.length() < 32 ){
		  hashtext = "0"+hashtext;
		}
		this.heslo = hashtext;
	}
	public String getSkupina() {
		return skupina;
	}
	
	public void setSkupina(String skupina) {
		this.skupina = skupina;
	}
	
	public int getId() {
		return id;
	}
	
	public void setId(int id) {
		this.id = id;
	}	
}
